Using multiple keys for git
Problem
Sometimes you'll have multiple github, gitlab, azure accounts and you'll have multiple ssh keys for each of those
Solution
Use ssh keys and define aliases in ssh config
How?
- Generate ssh keypairs and add to each of your account
Edit/Create ssh config file (
$HOME/.ssh/config
)Host github.com HostName github.com IdentityFile ~/.ssh/rsa_github IdentitiesOnly Yes Host gitlab.com HostName gitlab.com IdentityFile ~/.ssh/rsa_gitlab IdentitiesOnly Yes Host azure.com HostName azure.com IdentityFile ~/.ssh/rsa_azure IdentitiesOnly Yes
Test the connection
ssh -T git@github.com ssh -T git@gitlab.com ssh -T git@azure.com